package com.ruoyi.web;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://101.34.235.186:3306/music", "root", "Srcb@1234");
        String sql = "SELECT m_id, m_name, m_date FROM music";
        PreparedStatement statement = conn.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            int mId = resultSet.getInt(1);
            String mName = resultSet.getString(2);
            String date = resultSet.getString(3);
            System.out.println(date.substring(0, 10));
            String insertSql = "INSERT INTO `music`.`sys_song` (`name`, `singer`, `type`, `date`, `order_num`, `create_time`) VALUES (?,?,?,?,?,?);";
            PreparedStatement preparedStatement = conn.prepareStatement(insertSql);
            preparedStatement.setString(1, mName);
            preparedStatement.setString(2, "kiki");
            preparedStatement.setInt(3, 1);
            preparedStatement.setString(4, date.substring(0, 10));
            preparedStatement.setInt(5, mId);
            preparedStatement.setString(6, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            boolean execute = preparedStatement.execute();
        }
    }

}
